package com.yuhs.zixing.study.thread.juc.code003;

import lombok.SneakyThrows;

import java.util.concurrent.TimeUnit;

/**
 * @description
 * @author: yuhs
 * @date 2021/11/21 3:21 下午
 */
public class C01_Volatile001 {

    /*volatile*/ Boolean turning = Boolean.TRUE;

    void m() {
        System.out.println(Thread.currentThread().getName() + " 开始");
        while (turning) {
        }
        System.out.println(Thread.currentThread().getName() + " 结束");
    }

    @SneakyThrows
    public static void main(String[] args) {
        C01_Volatile001 volatile001 = new C01_Volatile001();
        new Thread(volatile001::m, "volatile001线程").start();
        TimeUnit.SECONDS.sleep(1);
        volatile001.turning = Boolean.FALSE;
    }

}
